package com.elcl.network;

import com.elcl.storage.SharedPreferencesUtils;

/**
 * 应用的基本配置信息
 */
public class AppContext {
    private static Long uid;// 用户当前的id
    private static String user_info;// 用户的个人信息
    private static Integer user_type;// 用户的姓名
    private static String token;// token
    private static String confing;//配置的

    private static Boolean isFirstLogin;//是否第一次装机

    private static String pushId;//所属经销商的id

    private static String appKey;//
    private static String appId;//

    private static String orderId;//订单的id

    /**
     * 获得当前用户的UID
     *
     * @return
     */
    public static Long getUid() {
        if (uid == null) {
            uid = SharedPreferencesUtils.getMemorySP(AppConstant.USER_ID, 0L,
                    Long.class);
        }
        return uid;
    }

    public static void setUid(long uid) {
        AppContext.uid = uid;
        SharedPreferencesUtils.setMemorySP(AppConstant.USER_ID, uid);
    }

    /**
     * 获得当前用户的资料（存储的是一个json）
     *
     * @return
     */
    public static String getUerInfo() {
        if (user_info == null) {
            user_info = SharedPreferencesUtils.getMemorySP(
                    AppConstant.USER_INFO, "", String.class);
        }
        return user_info;
    }

    public static void setUserInfo(String user_info) {
        AppContext.user_info = user_info;
        SharedPreferencesUtils.setMemorySP(AppConstant.USER_INFO, user_info);
    }

    /**
     * 获得当前用户的姓名
     *
     * @return
     */
    public static Integer getUerType() {
        if (null == user_type) {
            user_type = SharedPreferencesUtils.getMemorySP(
                    AppConstant.USER_TYPE, 0, Integer.class);
        }
        return user_type;
    }

    public static void setUerType(Integer user_type) {
        AppContext.user_type = user_type;
        SharedPreferencesUtils.setMemorySP(AppConstant.USER_TYPE, user_type);
    }


    /**
     * 获得当前用户的token
     * @return
     */
    public static String getToken() {
        if (token == null) {
            token = SharedPreferencesUtils.getMemorySP(
                    AppConstant.TOKEN, "", String.class);
        }
        return token;
    }

    public static void setToken(String token) {
        AppContext.token = token;
        SharedPreferencesUtils.setMemorySP(AppConstant.TOKEN, token);
    }


    /**
     * 获得当前推送的id
     * @return
     */
    public static String getPushId() {
        if (pushId == null) {
            pushId = SharedPreferencesUtils.getMemorySP(
                    AppConstant.PUSH_ID, "", String.class);
        }
        return pushId;
    }

    public static void setPushId(String pushId) {
        AppContext.pushId = pushId;
        SharedPreferencesUtils.setMemorySP(AppConstant.PUSH_ID, pushId);
    }

    /**
     * 获得配置的信息
     * @return
     */
    public static String getConfing() {
        if (confing == null) {
            confing = SharedPreferencesUtils.getMemorySP(
                    AppConstant.CONFING, "", String.class);
        }
        return confing;
    }

    public static void setConfing(String confing) {
        AppContext.confing = confing;
        SharedPreferencesUtils.setMemorySP(AppConstant.CONFING, confing);
    }

    /**
     * 是否第一次装机
     * @return
     */
    public static Boolean getIsFirstLogin() {
        if (isFirstLogin == null) {
            isFirstLogin = SharedPreferencesUtils.getMemorySP(
                    AppConstant.IS_FIRST_LOGIN, true, Boolean.class);
        }
        return isFirstLogin;
    }

    public static void setIsFirstLogin(Boolean isFirstLogin) {
        AppContext.isFirstLogin = isFirstLogin;
        SharedPreferencesUtils.setMemorySP(AppConstant.IS_FIRST_LOGIN, isFirstLogin);
    }


    /**
     * 经度
     * @return
     */
    public static String getAppKey() {
        if (appKey == null) {
            appKey = SharedPreferencesUtils.getMemorySP(
                    AppConstant.LONGITUDE, "", String.class);
        }
        return appKey;
    }

    public static void setAppKey(String appKey) {
        AppContext.appKey = appKey;
        SharedPreferencesUtils.setMemorySP(AppConstant.LONGITUDE, appKey);
    }

    /**
     * 纬度
     * @return
     */
    public static String getAppId() {
        if (appId == null) {
            appId = SharedPreferencesUtils.getMemorySP(
                    AppConstant.LATITUDE, "", String.class);
        }
        return appId;
    }

    public static void setAppId(String appId) {
        AppContext.appId = appId;
        SharedPreferencesUtils.setMemorySP(AppConstant.LATITUDE, appId);
    }


    /**
     * 订单的id，用在上传位置的时候，在service里上传
     * @return
     */
    public static String getOrderId() {
        if (orderId == null) {
            orderId = SharedPreferencesUtils.getMemorySP(
                    AppConstant.ORDER_ID, "", String.class);
        }
        return orderId;
    }

    public static void setOrderId(String orderId) {
        AppContext.orderId = orderId;
        SharedPreferencesUtils.setMemorySP(AppConstant.ORDER_ID, orderId);
    }



}
